/** @jsxImportSource @emotion/react */
import * as React from "react";
import { OriginalViewProps, } from "../../common/base";
import {
    EntranceSetup, config设备概况, config观测数据, config路线坡度, config行驶速度, config驻车制力, config踏板力, config绝缘阻,
} from "./orcBase";
import {createItem, } from "../../common/eHelper";
import {useRecordList} from "../../hook/useRecordList";
import {setupItemAreaRoute} from "./orcIspConfig";
import {EditStorageContext} from "../../StorageContext";
import {Text, useTheme} from "customize-easy-ui-component";
import {ItemRecheckOmniOther, } from "../../common/editor";
import {ItemInstrumentTable} from "../../common/Instrument";
import {DeviceSurvey, } from "../../elevator/editor";
import {FrontCover, ItemConclusion, } from "../../mobilecr/editorIN";
import {WitnessAmusM} from "../../amusement/editorJj";
import {ActionMapItemLikeAmuse} from "../../amusement/ActionMapItemLikeAmuse";
import {ObservationMeasureTourIn} from "./editMeasu";
import {BrakingDistance} from "./BrakingDistance";
import {SiteConditionSund} from "../../elevator/sundryDj/editor";
import {MeasureCritMem} from "../../hook/useMeasure";


const inNode_A1=<>
        <hr/>
        b.连续20m路段坡度(用水平仪测量时填写在下列表格中） &gt;
    </>;
export const tItems现场=[
    ['1、露天检验应在无雨雪情况下',{f:'T',
        N: <Text>1、露天检验应在无雨雪情况下进行；</Text>},],
    ['2、使用单位的检验前准备工作',{f:'p',
        N: <Text>2、使用单位的检验前准备工作应当满足检验要求。</Text>},],
    ['3、场地条件符合，不得处危险',{f:'D',
        N: <Text>3、现场的环境和场地条件符合检验要求，不得处于危险场所（如爆炸性环境），没有影响检验的物品、设施等，并且设置相应的警示标志</Text>},],
    ['4、不应有检验可能危及检验员',{f:'s',
        N: <Text>4、现场应具备安全检验条件，不应有开展检验可能危及检验人员或者他人安全和健康的因素存在。</Text>},],
];
const 大备注可选=["",];


const recordPrintList =[
    createItem('Entrance', <EntranceSetup/>),
    createItem('FrontCover', <FrontCover/>),
    createItem('Instrument', <ItemInstrumentTable label={'一、主要检验仪器设备性能检查'} />),
    createItem('Survey', <DeviceSurvey config={config设备概况} label={'二、设备概况'}>
            </DeviceSurvey>),
    createItem('Item', null),
    //原来名字：“四、首次检验不合格项目记录”
    createItem('ReCheck', <ItemRecheckOmniOther label={'四、 检验不合格项目内容'} setup={setupItemAreaRoute}/>),
    createItem('Conclusion', <ItemConclusion startd={false} label={'五、综合结论'}/>),
    createItem('Witness', <WitnessAmusM label={'七、备注'} datalist={大备注可选}>
            <>注：特殊情况，应在备注中说明检验员所负责检验的项目编号。</>
            <>注：本备注栏的内容在检验报告附件的备注栏内体现。</>
            </WitnessAmusM>),
    createItem('Measure', <MeasureCritMem config={config观测数据} label={'八、观测数据及测量结果记录表'}>
          </MeasureCritMem>),
    createItem('MeasureA1', <ObservationMeasureTourIn config={config路线坡度} label={'附录A1:行驶路线坡度检测'} inIdx={2} inNode={inNode_A1}/>),
    createItem('MeasureA2', <MeasureCritMem config={config行驶速度} label={'附录A2:最大行驶速度检测'}/>),
    createItem('MeasureA3', <MeasureCritMem config={config驻车制力} label={'附录A3:驻车制动操作力检测'}/>),

    createItem('BrakingDistance', <BrakingDistance label={'附录A4:行车制动距离测量'}/>),
    createItem('MeasureA5', <MeasureCritMem config={config踏板力} label={'附录A5:行车制动踏板力检测'}/>),
    createItem('MeasureA6', <MeasureCritMem config={config绝缘阻} label={'附录A6:绝缘电阻检测'}/>),
    createItem('SiteCondition', <SiteConditionSund config={tItems现场} label={'附录B：现场检验条件确认'}/>),
];


export const OriginalView=
  React.forwardRef((
    { action,  verId, repId='', rep,}
    :OriginalViewProps, ref
  ) => {
    const context =React.useContext(EditStorageContext);
    if(context == null)    throw new Error("EditStorageContext没有提供");
    const {storage, } =context;
    const theme = useTheme();
    //impressionismAs若有动态增加的编辑区就会可能出现hook报错！！干脆固定加一个空的区域（用户项目有没有都会出现的编辑区也即对应createItem()）。
    //初始化，印象派形式的动态构建的项目列表： 目前只有一个的印象派扩展标签。
    const recordPrintListNow =React.useMemo(() => {
      let routeAreas=[] as any[];
      const impressionismAs =setupItemAreaRoute({rep, orc:storage, theme});
      let extendTags =Reflect.ownKeys(impressionismAs) as string[];
      const oldItCount=recordPrintList.length;
      let prevpos=0;
      for(let p=0; p<oldItCount; p++){
        if(extendTags.indexOf(recordPrintList[p].itemArea)>=0){     //需要展开 扩充的标签
            routeAreas=routeAreas.concat(recordPrintList.slice(prevpos,p));
            const itemConfigs= impressionismAs?.[recordPrintList[p].itemArea];
            let seq = 0;
            let moreItems = [] as any;
            //动态 扩充{检验项目配置办法的}编辑区： 目前只有一个的印象派扩展标签ItemArs对应的是'Item-'。 ['Item-', ]
            itemConfigs.forEach((area, x) => {
              seq += 1;
              const rowHead =<ActionMapItemLikeAmuse key={seq} alone={false} editAreasConf={itemConfigs}
                                                     index={x}   />;
              moreItems.push(createItem(area.tag, rowHead));
            });
            routeAreas=routeAreas.concat(moreItems);
            prevpos=p+1;
        }
      }
      routeAreas=routeAreas.concat(recordPrintList.slice(prevpos));
      return routeAreas;
    }, [verId, repId,rep, storage?._Oitems, theme]);

    const {list}=useRecordList(ref,rep,recordPrintListNow,action,verId);

    return <React.Fragment>
      {list}
    {/*      <Button  intent="primary"
               onPress={(e) => { handleSubmit!();
               }}
      >送打印转换器
      </Button>*/}
    </React.Fragment>;
  } );

